package com.hb.trade.server.project.section.manager;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hb.core.pojo.enums.SignupStatusEnum;
import com.hb.core.pojo.project.section.dto.ProblemDTO;
import com.hb.core.pojo.project.section.dto.SupplyBidSignupDTO;
import com.hb.core.pojo.project.section.entity.SupplyBidSignup;
import org.fzzn.core.util.Enums;

import java.util.List;

/**
 * describe:
 *  投标人报名记录的Manager
 * @author zhongdl
 * @date 2021/12/21
 */
public class SupplyBidSignupManager extends SupplyBidSignupDTO {


    /**
     *
     * @Description:  泛型SupplyBidSignup 转换为 SupplyBidSignupDTO
     * @Author: zhongdl
     * @Date:2021/12/21 14:57
     * @param supplyBidSignups:
     * @return: {@link List< SupplyBidSignupDTO> }
     **/
    public static List<SupplyBidSignupDTO> changeSupplyBidSignupDTO(List<SupplyBidSignup> supplyBidSignups){
        List<SupplyBidSignupDTO> supplyBidSignupDTOS = CollUtil.list(false);
        if (CollUtil.isEmpty(supplyBidSignups)){
            return supplyBidSignupDTOS;
        }
        for (SupplyBidSignup supplyBidSignup : supplyBidSignups) {
            SupplyBidSignupDTO supplyBidSignupDTO = supplyBidSignup.to(SupplyBidSignupDTO.class);
            //已通过
            if (Enums.equals(SignupStatusEnum.REGISTERED,supplyBidSignupDTO.getSignupStatus())){
                supplyBidSignupDTO.setSignupStatusName("已通过");
            // 未通过
            }else if (Enums.equals(SignupStatusEnum.REG_FAILED,supplyBidSignupDTO.getSignupStatus())){
                supplyBidSignupDTO.setSignupStatusName("未通过");
            //待确认
            }else if (Enums.equals(SignupStatusEnum.REG_PROGRESS,supplyBidSignupDTO.getSignupStatus())){
                supplyBidSignupDTO.setSignupStatusName("待确认");
            }else {
                supplyBidSignupDTO.setSignupStatusName(Enums.nameOf(SignupStatusEnum.class,supplyBidSignupDTO.getSignupStatus()));
            }
            supplyBidSignupDTOS.add(supplyBidSignupDTO);
        }
        return supplyBidSignupDTOS;
    }

    public static QueryWrapper<SupplyBidSignup> fillCondition(SupplyBidSignupDTO supplyBidSignup){
        QueryWrapper<SupplyBidSignup> wrapper = wrapper();
        //公司名称
        if (StrUtil.isNotEmpty(supplyBidSignup.getOrgName())){
            wrapper.like("org_name",supplyBidSignup.getOrgName());
        }
        //联系人姓名
        if (StrUtil.isNotEmpty(supplyBidSignup.getContactName())){
            wrapper.like("contact_name",supplyBidSignup.getContactName());
        }
        //报名状态
        if (supplyBidSignup.getSignupStatus() != null){
            wrapper.eq("signup_status",supplyBidSignup.getSignupStatus() );
        }
        //设置标段id
        wrapper.eq("section_id",supplyBidSignup.getSectionId());
        wrapper.ne("signup_status",SignupStatusEnum.UN_REGISTERED.getCode());
        return wrapper;
    }


}
